<template>
  <div>
    <h2 class="title">{{$t('我的账户')}}</h2>
    <div>
      <div class="account-line">
        <span class="account-line-name">{{$t('昵称')}}</span>
        <p>
          <span class="account-line-value"> {{ userInfo.user_name }}</span>
        </p>
      </div>
      <div class="account-line">
        <span class="account-line-name">ID：</span>
        <p>
          <span class="account-line-value">{{ userInfo.id }}</span>
        </p>
      </div>
      <div class="account-line">
        <span class="account-line-name">{{$t('手机号')}}：</span>
        <p class="account-line-right">
          <span class="account-line-value">{{ userInfo.phone }}</span>
          <span @click="uPhoneShow()">{{$t('修改')}}</span>
        </p>
      </div>
      <div class="account-line">
        <span class="account-line-name">{{$t('登录密码')}}：</span>
        <p class="account-line-right">
          <span class="account-line-value">******</span>
          <span @click="uLoginPasswordShow()">{{$t('修改')}}</span>
        </p>
      </div>

      <ULoginPassword ref="uLoginPassword" @onConfirm="uLoginPasswordConfirm"></ULoginPassword>
      <UPhone ref="uPhone" @onConfirm="uPhoneConfirm"></UPhone>

      <Button type="error" class="logout-btn" @click="signOut">{{$t('退出登录')}}</Button>
    </div>
  </div>
</template>

<script>
import store from "@/vuex/store";
import { mapState, mapActions } from "vuex";
export default {
  name: "MyAccount",
  data() {
    return {
      comName: "",
      theme: "light",
    };
  },
  components: {
    ULoginPassword:()=>import('@/components/account/uLoginPassword'),
    UPhone:()=>import('@/components/account/uPhone')
  },
  mounted() {
    if (this.$route.query.isBindPhone === '1' && !this.userInfo.phone) {
      setTimeout(() => {
        this.uPhoneShow()
      }, 300)
    }
  },
  methods: {
    ...mapActions(['signOut']),
    
    /**
     * 获取个人信息
     */
    getUserInfo(){
      this.$http.getUserInfo().then(res=>{
        if(res.status===200){
          this.userinfo = res.data
        }
      })
    },

    /**
     * 打开修改手机号弹框
     */
    uPhoneShow(){
      let params={current_phone:this.userInfo.phone}
      this.$refs.uPhone.handleRender(params);
    },

    /**
     * 打开修改密码弹框
     */
     uLoginPasswordShow(){
      let params={current_phone:this.userInfo.phone}
      this.$refs.uLoginPassword.handleRender(params);
     },
    
    /**
    * 修改登录密码
    */
    uLoginPasswordConfirm(){
      
      // this.$refs.addressRef.onCancel();//关闭弹窗
    },

    /**
     * 修改手机号
     */
    uPhoneConfirm(){
      this.$store.dispatch('getUserInfo')
    },
  },
  computed: {
    ...mapState(["userInfo"]),
  },
};
</script>


<style lang="scss" scoped>
@import "@/common/style/common.scss";
.account {
  &-line {
    padding: 15px;
    border-bottom: 1px solid #eee;
    @include flex();
    &-name {
      width: 80px;
      display: inline-block;
    }
    &-value {
      font-size: 16px;
      font-weight: 500;
    }
    &-right {
      @include flex($jc: space-between);
      flex-wrap: nowrap;
      width: 90%;
    }
  }
}
.title {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  font-size: 20px;
  color: #333;
  font-weight: 600;
  margin-bottom: 30px;
}
.logout-btn{
  margin-top: 30px;
  float:right
}
</style>
